/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.alag.ci.webscrawler;
import java.net.MalformedURLException;
import java.net.URL;

/**
 *
 * @author sczbbx
 */
public class CrawlerUrl {
    
    private int depth = 0;
    private String urlString = null;
    private URL url = null;
    private boolean isAllowedToVisit;
    private boolean isCheckedForpermission = false;
    private boolean isVisited = false;
    
    public CrawlerUrl(String urlString, int depth) {
        this.urlString = urlString;
        this.depth = depth;
        computeURL();
    }

    private void computeURL() {
        try {
            url = new URL(urlString);
        }
        catch(MalformedURLException e) {
            //wrong things happened
        }
    }
    
    public URL getURL() {
        return this.url;
    }
    
    public int getDepth() {
        return this.depth;
    }
    
    public boolean isAllowedToVisit() {
        return this.isAllowedToVisit;
    }

    /**
     * @param isAllowedToVisit the isAllowedToVisit to set
     */
    public void setAllowedToVisit(boolean isAllowedToVisit) {
        this.isAllowedToVisit = isAllowedToVisit;
        this.isCheckedForpermission = true;
    }

    /**
     * @return the isCheckedForpermission
     */
    public boolean isCheckedForpermission() {
        return isCheckedForpermission;
    }
    /**
     * @return the isVisited
     */
    public boolean isVisited() {
        return isVisited;
    }

    /**
     * @param isVisited the isVisited to set
     */
    public void setIsVisited() {
        this.isVisited = true;
    }
    
    public String getUrlString() {
        return this.urlString;
    }
    
    @Override
    public String toString() {
        return this.urlString + " [depth=" + depth + " visit="
                + this.isAllowedToVisit + " check="
                + this.isCheckedForpermission() + "]";
    }
    
    @Override
    public int hashCode() {
        return this.urlString.hashCode();
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj.getClass() != this.getClass()) {
            return false;
        }
        return obj.hashCode() == this.hashCode();
    }
    
}
